package com.zhongwang.mms.module.jiaGongStorage.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.TWarehouseInfo;
import com.zhongwang.mms.module.jiaGongStorage.model.JStorageInventory;
import com.zhongwang.mms.module.jiaGongStorage.service.StorageInService;
import com.zhongwang.mms.module.jiaGongStorage.service.StorageStockQueryService;
import com.zhongwang.mms.module.overview.dao.OveIndexDao;
import com.zhongwang.mms.module.purchase.dao.PurWarInManageDao;
import com.zhongwang.mms.module.purchase.model.PChangeOrderModel;
import com.zhongwang.mms.module.purchase.model.PurInvQueryModel;
import com.zhongwang.mms.module.purchase.service.PurlnvQueryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @Description: 库存综合查询
 * @Author: China.zh
 * @Date: 2020/4/6 12:53
 */
@Slf4j
@Controller
@RequestMapping("/jiaGongStockQuery")
public class StorageStockQueryController extends BaseController {

    @Autowired
    private PurlnvQueryService purlnvQueryService;
    @Autowired
    private PurWarInManageDao purWarInManageDao;
    @Autowired
    private OveIndexDao oveIndexDao;
    @Autowired
    private StorageInService storageInService;
    @Autowired
    private StorageStockQueryService storageStockQueryService;
    /**
     * 页面
     *
     * @return 页面路径
     */
    @GetMapping("/page")
    public String index(Model model) {
        List<TWarehouseInfo> warehouseInfoList =  storageInService.findWarehouseInfoList();;
        model.addAttribute("warehouseInfoList",warehouseInfoList);
        return "jiaGongStorage/storageStockQuery/page";
    }
    /**
     * 页面
     *
     * @return 页面路径
     */
    @GetMapping("/index/project/{code}")
    public String indexProject(@PathVariable("code") String code,Model model) {
        model.addAttribute("code",code);
        model.addAttribute("mode","pro");
        List<TWarehouseInfo> warehouseInfoList =  purWarInManageDao.findWarehouseInfoList();
        model.addAttribute("warehouseInfoList",warehouseInfoList);
        return "purchase/purInvManage/purInvQuery/page";
    }

    /**
     * 首页外购件库存总金额（含辽阳、营口机械备件库）跳转使用
     *
     * @return 页面路径
     */
    @GetMapping("/index/{type}")
    public String indexForJump(Model model,@PathVariable("type") String type) {
        String totalPrice = null;
        String title="";
        switch (type){
            case "all":
                title ="外购件库存总金额（含辽阳、营口机械备件库）";
                totalPrice = oveIndexDao.getInventoryInStockTotalAmountByPurchaseAndHalf().toString();
                model.addAttribute("mode",null);
                break;
            case "group":
                title ="集团物资部外购件库（库存金额："+oveIndexDao.getInventoryTotalAmountByPurchase().toString()+"万，项目在库金额："+oveIndexDao.getProjectInStockTotalAmountByPurchase().toString()+"万，库存在库金额："+oveIndexDao.getInventoryInStockTotalAmountByPurchase().toString()+"万）";
//                totalPrice = "("+oveIndexDao.getInventoryTotalAmountByPurchase().toString()+","+
//                        oveIndexDao.getProjectInStockTotalAmountByPurchase().toString()+","+
//                        oveIndexDao.getInventoryInStockTotalAmountByPurchase().toString()+")";
                model.addAttribute("mode",null);
                break;
            case "groupByPro":
                title ="集团物资部外购件库项目在库金额";
                totalPrice = oveIndexDao.getProjectInStockTotalAmountByPurchase().toString();
                model.addAttribute("mode","pro");
                break;
            case "groupByInv":
                title ="集团物资部外购件库库存在库金额";
                totalPrice = oveIndexDao.getInventoryInStockTotalAmountByPurchase().toString();
                model.addAttribute("mode","inv");
                break;
        }

            model.addAttribute("totalPrice",totalPrice);
            model.addAttribute("title",title);
        List<TWarehouseInfo> warehouseInfoList =  purWarInManageDao.findWarehouseInfoList();
        model.addAttribute("warehouseInfoList",warehouseInfoList);
        return "purchase/purInvManage/purInvQuery/page";
    }

    /**
     * 页面
     *
     * @return 页面路径
     */
    @GetMapping("/index/query/{code}/{mode}")
    public String indexQuery(Model model, @PathVariable("code") String code,@PathVariable("mode") String mode) {
        List<TWarehouseInfo> warehouseInfoList =  purWarInManageDao.findWarehouseInfoList();
        model.addAttribute("warehouseInfoList",warehouseInfoList);
        model.addAttribute("code", code);
        model.addAttribute("mode", mode);
        return "purchase/purInvManage/purInvQuery/page";
    }

    /**
     * 列表
     *
     * @param param 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/querylist")
    public JsonResult list(JStorageInventory param) {
        startPage();
        List<JStorageInventory> list = storageStockQueryService.findPurInvList(param);
        return jsonResult(list);
    }


    /**
     * 列表 导出
     *
     * @param param 查询条件
     * @return list
     */
    @PostMapping("/exportExcel")
    @ResponseBody
    public JsonResult JsonResult(JStorageInventory param) throws IOException {
       return storageStockQueryService.exportExcel(param);
    }


}
